//202102104015柴亚楠
package util;

public class Pagination {
    public String toLimitClause(int totalNum){
        this.totalNum = totalNum;
        int offset = (this.pageNo - 1) * this.pageSize;
        return " LIMIT " + offset + ", " + this.pageSize;
    }

    public int getTotalPages(Pagination pagination){
        int totalPages = (int)((pagination.getTotalNum() - 1) / pagination.getPageSize() + 1);
        return totalPages;
    }

    public Pagination(int pageSize, int pageNo) {
        if(pageNo > 0) {
            this.pageNo = pageNo;
        }else{
            this.pageNo = 5;
        }

        if(pageSize > 0) {
            this.pageSize = pageSize;
        }else {
            this.pageSize = 1;
        }

    }
    public int getPageSize() {
        return pageSize;
    }

    public int getPageNo() {
        return pageNo;
    }

    public int getTotalNum() {
        return totalNum;
    }

    private int pageSize = 10000;
    private int pageNo = 1;
    private int totalNum = 1;

    @Override
    public String toString() {
        return "Pagination{" +
                "pageSize=" + pageSize +
                ", pageNo=" + pageNo +
                ", totalNum=" + totalNum +
                '}';
    }
}
